// index.js
// 获取应用实例
const app = getApp()
Page({
  data: {
    headerimg:"",
    photos:[],
    hidden:false,
    bottom:true,
    endnum:0
  },
  onLoad(e) {
    wx.showLoading({
      title: '加载中',
    })
    var that=this;
    //转译带参数二维码的id换成活动名称name
    var nid=e.id;
    if(nid != undefined){
      app.comrequest('https://live.ipass.cc/myapi2/livephoto/lpapi.php',{num:8,nid:nid}).then(res=>{
        that.setData({
          name:res[0].postername
        })
      })
    }else{
      that.setData({
        name:e.name
      })
    }
    that.setData({
      headerimg:e.url,
      url:e.url
    })
    setTimeout(()=>{
      // console.log(that.data.name)
      app.comrequest('https://live.ipass.cc/myapi2/livephoto/lpapi.php',{num:1,name:that.data.name}).then(res=>{
      // console.log(res.zg[0].zg)
        that.setData({
          photos:res.photos,
          zg:res.zg[0].zg
        })
      })
      wx.hideLoading()
    },500)
  },
  imgclick(e){
    var imgurl=e.currentTarget.dataset.url
    wx.navigateTo({
      url: '../imageurl/imageurl?imgurl='+imgurl,
    })
  },
  onShareAppMessage: function() {
    return {
      title:'上清古镇精彩瞬间',
      path:'pages/index/index?name='+this.data.name+'&url='+this.data.url,
      success:res=>{
        console.log('成功')
      },fail:res=>{
        console.log("失败")
      }
    }
  },
  onShareTimeline:function(){
      return {
          title:'上清古镇精彩瞬间',
          path:'pages/index/index?name='+this.data.name+'&url='+this.data.url,
          success:res=>{
            console.log('成功')
          },fail:res=>{
            console.log("失败")
          }
        }
  },
  onReachBottom: function () {
    var that=this
    that.setData({
      bottom:false
    })
    var endnum=that.data.endnum
    var imgs=that.data.zg
    if(endnum<imgs){
      that.setData({
        endnum:endnum+10
      })
      if(that.data.endnum>=imgs){
        that.setData({
          hidden:true,
        })
      }
    }
    
    setTimeout(()=>{
      app.comrequest('https://live.ipass.cc/myapi2/livephoto/lpapi.php',{num:7,endnum:that.data.endnum,name:that.data.name}).then(res=>{
        var photos=that.data.photos
        for(let i in res){
          photos.push(res[i])
        }
        that.setData({
          photos
        })
    })
    },600)

  }
  
})
